from  PyQt5.QtWidgets import *
import sys
class QlabelDemo(QDialog):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("Qlabel案例")
        namelabel1=QLabel('&name',self)
        nameed1=QLineEdit(self)
        namelabel1.setBuddy(nameed1)   #通过&让label标签和edit标签产生关联 alt+n
        namelabel2 = QLabel('password', self)
        nameed2 = QLineEdit(self)
        namelabel2.setBuddy(nameed2)
        btnok=QPushButton('ok')
        btnCancel=QPushButton('cancel')
        mainlayout=QGridLayout(self)#网格布局
        mainlayout.addWidget(namelabel1,0,0)
        mainlayout.addWidget(nameed1,0,1,1,2)
        mainlayout.addWidget(namelabel2,1,0)
        mainlayout.addWidget(nameed2,1,1,1,2)
        mainlayout.addWidget(btnok,2,1)
        mainlayout.addWidget(btnCancel,2,2)
if __name__ == '__main__':
    app=QApplication(sys.argv)
    labeldemo=QlabelDemo()
    labeldemo.show()
    sys.exit(app.exec_())